﻿using System;
using System.IO;

namespace TfsCommitMonitor
{
	internal static class DebugLogger
	{
		internal static void LogException(Exception exception)
		{
			if (!Directory.Exists(Configuration.AppConfigPath))
				Directory.CreateDirectory(Configuration.AppConfigPath);

			using (StreamWriter sw = new StreamWriter(Configuration.DebugFilePath, true))
			{
				sw.WriteLine("*** Exception Occured -- {0} {1} ***", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString());
				sw.WriteLine("Exception: {0}", exception.GetType().Name);
				sw.WriteLine("Message: {0}", exception.Message);
				sw.WriteLine("Stack Trace: {0}", exception.StackTrace);
				if (exception.InnerException != null)
					LogException(exception.InnerException);
			}
		}
	}
}
